<?php
ob_start();
require_once('../../FirePHPCore/FirePHP.class.php');
?>
<thead>
<?php
include '../../functions.php';
include '../../additionalFunctions.php';

$crops = explode(";",$_GET['crops']);
$year = $_GET['year'];
$attributes = $_GET['attributes'];
$attributesArray = explode(';',$attributes);
$selectedA = $_GET['selectedA'];

print "<tr><th></th><th>Month</th>";

$cropsFormatted = array();
$units = array();
foreach ($crops as $c) {
	$units[] = substr($c, strripos($c, " - ") + 3); // gets just the name of the unit
	$cropsFormatted[] = substr($c, 0, strripos($c, " - ")); // finds the last position of occurence of " - " ==> takes only the crop name, not the units
	print "<th>" . substr($c, 0, strripos($c, " - ")) . "</th>";// finds the last position of occurence of " - " ==> takes only the crop name, not the units
}

print "</tr></thead><tbody>";

for ($i = 1; $i <= 12; $i++) {
	$result = array();
	for ($k = 0; $k < count($crops); $k++) {
		$result[$k] = getRangeData($year."-".$i."-01",$year."-".$i."-".lastDayOfMonth($i),getCropId($cropsFormatted[$k]),$selectedA, getUnitId($units[$k]), $selectedA == 'sales' ? getCustomerId($_GET['customers']) : ($selectedA == 'amount_donated' ? getCustomerId($_GET['donationCustomers']) : NULL));
	}
	print "<tr><td id=\"td1\"><img id=\"".getMonth($i)."\" src=\"DataTables-1.7.3/details_open.png\" /></td><td id=\"td2\">".getMonth($i)."</td>";
	for ($j = 0; $j < count($crops); $j++) {
		$l = $j + 3;
		print "<td id=\"td".$l."\">$result[$j]</td>";
	}
	print "</tr>";
}

?>
</tbody>